<template>
  <el-dialog
    :title="title"
    center
    :visible.sync="visible"
    width="1200px"
    append-to-body
    custom-class="set-role-dialog"
  >
    <el-form ref="form" :model="form">
      <el-table height="615px" :data="form.list" border stripe>
        <el-table-column
          label="序号"
          align="center"
          prop="id"
          width="60"
        ></el-table-column>
        <el-table-column
          label="菜单功能"
          align="center"
          prop="menuName"
          width="180"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="操作权限" header-align="center" align="left">
          <template slot-scope="scope">
            <el-form-item :prop="`list.${scope.$index}.roles`">
              <el-checkbox-group v-model="scope.row.roles">
                <el-checkbox
                  v-for="item in scope.row.labels"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      title: "设置权限",
      visible: false,
      tableRow: null,
      form: {
        list: [
          {
            id: 1,
            menuName: "首页",
            labels: ["查看", "个人小应用", "填报日历小应用"],
            roles: ["个人小应用"],
          },
          {
            id: 2,
            menuName: "碳配额",
            labels: ["添加", "删除", "编辑", "导出", "保存", "下发碳配额"],
            roles: [],
          },
        ],
      },
    };
  },
  methods: {
    init({ row }) {
      this.tableRow = row;
      this.visible = true;
    },
    submitForm() {},
    cancel() {},
  },
};
</script>

<style lang="scss">
.set-role-dialog {
  .el-form-item {
    margin-bottom: 0;
  }
  .el-checkbox-group {
    display: flex;
    flex-wrap: wrap;
  }
}
</style>
